package com.teradata.params.controller;

import com.teradata.params.odatamodel.OdataModelParams;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试URL
 * http://localhost:8080/odata?$select=DEAL_DATE,PHONE_NO,SHOULD_PAY&$filter=DEAL_DATE eq 201801 and PHONE_NO contains ('139')&$orderby=DEAL_DATE,PHONE_NO&$top=30
 *
 * http://localhost:8080/odata?appId=app1001&apiName=GetUserInfo&apiVersion=1&$select=DEAL_DATE,PHONE_NO,SHOULD_PAY&$filter=DEAL_DATE eq 201801 and PHONE_NO contains ('139')&$orderby=DEAL_DATE,PHONE_NO&$top=30
 */
@RestController
public class OdataController {

    @GetMapping(name = "/odata")
    public OdataModelParams getParams(@RequestParam("$appId") String appId,@RequestParam("$apiName") String apiName,@RequestParam("$apiVersion") String apiVersion ,@RequestParam("$select") String select, @RequestParam("$filter") String filter, @RequestParam("$orderby") String orderby, @RequestParam("$top") String top) {
        System.out.println("appId:" + appId + " want access the " + apiName + ":" + apiVersion);

        //1.权限验证


        //2.odata
        OdataModelParams odataModelParams = new OdataModelParams();
        odataModelParams.setSelect(select);
        odataModelParams.setFilter(filter);
        odataModelParams.setOrderby(orderby);
        odataModelParams.setTop(top);
        System.out.println("The params is:" + odataModelParams);
        System.out.println("The select is:" + odataModelParams.getSelect());
        System.out.println("The where is:" + odataModelParams.getFilter());
        return odataModelParams;
    }

}
